<!DOCTYPE html>
<html class="iframe-h">

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>转手商城后台-用户管理</title>
		<link rel="stylesheet" type="text/css" href="../../static/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/css/admin.css" />

		<script src="../../static/js/public/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/jquery.session.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/util.js" type="text/javascript" charset="utf-8"></script>
		
		<script src="../../static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/common.children.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div class="wrap-container clearfix" id="list">
			<div class="column-content-detail">
				<form class="layui-form" @submit.prevent="onSubmit">
					<div class="layui-form-item">
						<div class="layui-inline tool-btn">
							<button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="user/user-add.html"><i class="layui-icon">&#xe654;</i></button>
							<button class="layui-btn layui-btn-small layui-btn-danger" @click="delAll()"><i class="layui-icon">&#xe640;</i></button>
						</div>
						<div class="layui-inline">
							<input type="text" name="text" placeholder="请输入查询内容" autocomplete="off" class="layui-input">
						</div>
						<button class="layui-btn layui-btn-normal search" lay-submit="search">搜索</button>
					</div>
				</form>
				<div class="layui-form" id="table-list">
					<table class="layui-table" lay-even lay-skin="nob">
						<colgroup>
							<col width="50">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
							<col width="150">
						</colgroup>
						<thead>
							<tr>
								<th><input type="checkbox" class="checkbox" name="checkboxAll" lay-skin="primary" lay-filter="allChoose"></th>
								<th>ID</th>
								<th>昵称</th>
								<th>电话</th>
								<th>邮箱</th>
								<th>创建时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="item in obj.list">
								<td><input :value="item.uid" class="checkbox" type="checkbox" name="checkbox" lay-skin="primary" data-id="1"></td>
								<td>{{item.uid}}</td>
								<td>{{item.name}}</td>
								<td>{{item.phone}}</td>
								<td>{{item.email}}</td>
								<td>{{item.registertime}}</td>
								<td>
									<div class="layui-inline">
										<button class="layui-btn layui-btn-small layui-btn-normal" data-id="1" @click="jump(item.uid)"><i
											 class="layui-icon">&#xe642;</i></button>
										<button class="layui-btn layui-btn-small layui-btn-danger" data-id="1" @click="del(item.uid)"><i
											 class="layui-icon">&#xe640;</i></button>
									</div>
								</td>
							</tr>
						</tbody>
					</table>
					<div class="page-wrap">
						<ul class="pagination">
							<li>
								<a href="javascript:;" @click="loadPage(1)">«</a>
							</li>
							<li v-if="obj.prePage > 0">
								<a href="javascript:;" @click="loadPage(obj.prePage)">{{obj.prePage}}</a>
							</li>
							<li class="active">
								<span>{{obj.pageNum}}</span>
							</li>
							<li v-if="obj.nextPage > 0">
								<a href="javascript:;" @click="loadPage(obj.nextPage)">{{obj.nextPage}}</a>
							</li>
							<li>
								<a href="javascript:;" @click="loadPage(obj.pages)">»</a>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>

		<script type="text/javascript">
			var size = 10;

			var vm = new Vue({
				el: '#list',
				data: {
					obj: {}
				},
				methods: {
					loadPage(num) { //加载记录
						var _this = this;
						axios({
							method: 'get',
							url: getRootURL() + 'admin/select-userlist',
							params: {
								pageNum: num,
								pageSize: size
							},
							headers: {
								'Authorization': $.session.get("token"),
								'Content-Type': 'application/x-www-form-urlencoded'
							}
						}).then(function(res) {
							console.log(res);

							if (res.data.status >= 0) {
								_this.obj = res.data.object
								reload()
							} else {
								alert(res.data.msg);
							}

						}).catch(function(err) {
							alert(err);
						});
					},
					del(id) { //删除用户记录
						var _this = this;
						alert("是否删除用户?", function() {
							axios({
								method: 'post',
								url: getRootURL() + 'admin/delect-user',
								params: {
									uid: id
								},
								headers: {
									'Authorization': $.session.get("token"),
									'Content-Type': 'application/x-www-form-urlencoded'
								}
							}).then(function(res) {
								console.log(res);

								if (res.data.status >= 0) {
									alert(res.data.msg, function() {
										if (_this.$data.total == 1 && _this.$data.pageNum - 1 != 0) {
											_this.loadPage(_this.$data.pageNum - 1);
										} else {
											_this.loadPage(_this.$data.pageNum);
										}
									});
								} else {
									alert(res.data.msg);
								}

							}).catch(function(err) {
								alert(err);
							});
						});
					},
					delAll() { //批量删除用户
						var _this = this;
						var uid = '' //需要拼接处理
						$("input[name='checkbox']:checked").each(function() {
							uid = uid + $(this).val() + ","
						});
						uid = uid.substring(0, uid.length - 1);
						console.log(uid)

						alert("是否批量删除用户?", function() {
							axios({
								method: 'post',
								url: getRootURL() + 'admin/batch-delete-user',
								params: {
									uid: uid
								},
								headers: {
									'Authorization': $.session.get("token"),
									'Content-Type': 'application/x-www-form-urlencoded'
								}
							}).then(function(res) {
								console.log(res);

								if (res.data.status >= 0) {
									alert(res.data.msg, function() {
										//取消复选框选中
										 layui.use([ 'layer', 'jquery', 'form'], function() {
											 $ = layui.jquery;
											 var form = layui.form();
											 $(".checkbox").prop("checked", false);
											 form.render('checkbox');
										 })
										  
										if (_this.$data.total == 1 && _this.$data.pageNum - 1 != 0) {
											_this.loadPage(_this.$data.pageNum - 1);
										} else {
											_this.loadPage(_this.$data.pageNum);
										}
									});
								} else {
									alert(res.data.msg);
								}

							}).catch(function(err) {
								alert(err);
							});
						});
					},
					jump(id){
						$.session.set("uid",id),
						$(location).attr('href', 'user-detail.html');
					},
					onSubmit() {
						//防止form冒泡
						return false;
					}

				},
				created() {
					this.loadPage(1)
				},
				mounted() {

				}
			})
		</script>

	</body>

</html>
